<?php

class Users_Model_Access_Rule_Storage_Table extends Workset_Model_Object_Storage_Table_Abstract {

	protected $_objectClass 		= 'Users_Model_Access_Rule';

	protected $_tableClass 			= 'Users_Table_Access_Rule';

	protected $_iteratorClass 		= 'Workset_Model_Object_Iterator';

    protected $_linkedObjectTableClass = 'Users_Table_Access_Role';

	function linkToObject(Workset_Model_Object_Interface $object, Workset_Model_Object_Interface $refObject) {
        $row = $object->getData();
        if ($row instanceof Workset_Db_Table_Row) {
            return $row->addDependentRow($this->_linkedObjectTableClass, array(
                'role_id' => $refObject->getId(),
            ));
        }
    }

    function unlinkObject(Workset_Model_Object_Interface $object, Workset_Model_Object_Interface $refObject) {
        $row = $object->getData();
        if ($row instanceof Workset_Db_Table_Row) {
            $subrow = $row->findDependentRow($this->_linkedObjectTableClass, 'privilege', array(
                'role_id' => $refObject->getId(),
            ));
            if ($subrow) {
                return $subrow->delete();
            }
        }
    }

}

?>